package com.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.CellFormat;
import jxl.write.Formula;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCell;
import jxl.write.WritableCellFeatures;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.util.BODY;
import com.util.ConfigUtil;
import com.util.Constant;
import com.util.ExcelUtil;
import com.util.JSONUtil;
import com.util.OpenKey;
import com.util.SessionInfo;
import com.util.Util;

/**
 * 基数核定
 * @author 
 */
@Controller
@RequestMapping("/jshdcontroller")
public class JSHDController {
	@RequestMapping("/test")
	@ResponseBody
	 public String upload( HttpServletRequest request, String name,@RequestParam("file") MultipartFile file,HttpSession session,HttpServletResponse response) throws IOException{  
	        String path = request.getSession().getServletContext().getRealPath("upload");  
	        String fileName = file.getOriginalFilename();//获取到上传文件的名字
	        //System.out.println(file.getName()+"2222");获取到file
	        //file.getSize();获取到上传文件的大小
	        String destPath = Constant.PK_FILEPATH + "gjbg/tmp/";	  
	        SimpleDateFormat s=new SimpleDateFormat("yyyyMMddHHmmSS");
	        
	        File dir = new File(destPath,fileName+s.format(new Date()) );
	        if(!dir.exists()){  
	            dir.mkdirs();  
	            file.transferTo(dir);  
	        }  
	        //MultipartFile自带的解析方法  
	        
	        Sheet sheet;
	        Workbook book;
	        Cell cell1,cell2,cell3;
	        try { 
	            //t.xls为要读取的excel文件名
	            book= Workbook.getWorkbook(dir); 
	            
	            //获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2,3,....)
	            sheet=book.getSheet(0); 
	            //获取左上角的单元格
	            cell1=sheet.getCell(0,0);
	            
	            cell1=sheet.getCell(1,1);//（列，行）
                cell2=sheet.getCell(1,2);
                cell3=sheet.getCell(1,3);
                Cell c00 = sheet.getCell(1, 3);
                String sxdate = c00.getContents().trim();
                System.out.println(cell3.getContents()+cell1.getContents()+cell2.getContents()+c00.getContents());
                List listRet=new ArrayList();
    			if (sxdate == null || sxdate.length() != 10) {
    				Map map1 = new HashMap();
    				map1.put("msg","请正确填写基数变更生效时间，格式为 yyyy-mm-dd ，例如：2014-02-01 为2014年2月1日 ！！！");
    				listRet.add(map1);
    		
    			}else{
    			if (!Util.isInteger(sxdate.substring(0, 4))
    					|| Integer.parseInt(sxdate.substring(0, 4)) < 2010
    					|| Integer.parseInt(sxdate.substring(0, 4)) > 2020
    					|| sxdate.charAt(4) != '-'
    					|| !Util.isInteger(sxdate.substring(5, 7))
    					|| Integer.parseInt(sxdate.substring(5, 7)) < 1
    					|| Integer.parseInt(sxdate.substring(5, 7)) > 12
    					|| sxdate.charAt(7) != '-'
    					|| !Util.isInteger(sxdate.substring(8, 10))
    					|| Integer.parseInt(sxdate.substring(8, 10)) < 1
    					|| Integer.parseInt(sxdate.substring(8, 10)) > 31) {
    				Map map = new HashMap();
    				map.put("code", 0);
    				map.put("msg", "请正确填写请正确填写基数变更生效时间，格式为 yyyy-mm-dd ，例如：2014-02-01 为2014年2月1日 ！！！");
    				map.put("data", "");
    				listRet.add(map);
    				// listRet.add("请正确填写基数变更生效时间，格式为 yyyy-mm-dd ，例如：2014-02-01 为2014年2月1日 ！！！");
    			}
    			
    			c00 = sheet.getCell(4, 4);// 第一个是列数，第二个是行数
    			// System.out.println(c00.getContents());
    			String p_grbl = c00.getContents().trim();

    			c00 = sheet.getCell(2, 4);// 第一个是列数，第二个是行数
    			// System.out.println(c00.getContents());
    			String p_dwbl = c00.getContents().trim();

    			if (p_grbl == null || p_dwbl == null
    					|| Integer.parseInt(p_grbl) > 20
    					|| Integer.parseInt(p_dwbl) > 20) {
    				Map map = new HashMap();
    				map.put("code", 0);
    				map.put("msg", "请正确填写单位比例及个人比例！！！");
    				map.put("data", "");
    				listRet.add(map);
    			}
    			sxdate = sxdate.substring(0, 8) + "01";

    			c00 = sheet.getCell(1, 2);// 第一个是列数，第二个是行数
    			// System.out.println(c00.getContents());
    			String dwdm = c00.getContents().trim();
    			
    			SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
    			BODY b=new BODY();
    			b.setDWZH(dwdm);
    			Map reqMap=new HashMap();
    			reqMap.put("AUTHORITY", "YBGJJ185");
    			reqMap.put("OpenKey", sessionIn.getKEY());
    			reqMap.put("BODY",b);
    			OpenKey opk=new OpenKey();
    			String result=opk.getOpenKey(reqMap, session);
    			Map resMap = JSONUtil.toMap(result);
    			if(resMap.get("RETURNCODE").toString().equals("100"))
    			{
    				
    				Map mapt=(Map) resMap.get("body");
    				List listzcxx=(List) mapt.get("RETDATA");
    				 int j=8;
    		            while(true){
    		            	cell1=sheet.getCell(0,j);
    		            	if("".equals(cell1.getContents())==true)    //如果读取的数据为空
    		                    break;
    		            	else
    		            		j++;
    		            	
    		            }
    		            System.out.println(j);
    		           
    		            	for(int i=8;i<j;i++){
    		            		Cell[] cells2 = sheet.getRow(i);
    		            		String grzh = cells2[3].getContents().trim();
    		            		Map reqMap1=new HashMap();
    		        			reqMap1.put("AUTHORITY", "YBGJJ186");
    		        			reqMap1.put("OpenKey", sessionIn.getKEY());
    		        			b.setDWZH(dwdm);
    		        			b.setZJHM(cells2[2].getContents().trim() );
    		        			b.setGRZH(grzh);
    		        			reqMap1.put("BODY",b);
    		        			OpenKey opk1=new OpenKey();
    		        			String result1=opk1.getOpenKey(reqMap1, session);
    		        			Map resMap1 = JSONUtil.toMap(result1);
    		        			 String errorMsg = "";
    		        			 if(!resMap1.get("RETURNCODE").toString().equals("100"))
    		        			 errorMsg=errorMsg+resMap1.get("RETURNDESC").toString();
    		            			String grbl = cells2[11].getContents().trim();

//    		    					if (!Util.isInteger(grbl))
//    		    						errorMsg = errorMsg + " 个人缴存比例不是整数。";
//    		    					else if (Integer.parseInt(grbl) > 20)
//    		    						errorMsg = errorMsg + " 个人缴存比例不能超过20%。";
    		    //
//    		    					String dwbl = cells2[12].getContents().trim();
//    		    					if (!Util.isInteger(dwbl))
//    		    						errorMsg = errorMsg + " 单位缴存比例不是整数。";
//    		    					else if (Integer.parseInt(dwbl) > 20)
//    		    						errorMsg = errorMsg + " 单位缴存比例不能超过20%。";
    		    					String mobile = cells2[15].getContents().trim();
    		    					String grjce_gr = cells2[14].getContents().trim();
    		    					if(grjce_gr==null||grjce_gr.trim().equals("")){
    		    						errorMsg = errorMsg + " 无效的个人缴存额 ";
    		    					}
    		    					String dwjce_gr = cells2[15].getContents().trim();
    		    					if(dwjce_gr==null||dwjce_gr.trim().equals("")){
    		    						errorMsg = errorMsg + " 无效的单位缴存额 ";
    		    					}
    		    					if(grjce_gr!=null&&!grjce_gr.trim().equals("")&&dwjce_gr!=null&&!dwjce_gr.trim().equals("")){
    		    						if(Double.parseDouble(grjce_gr.replaceAll(",", ""))+Double.parseDouble(dwjce_gr.replaceAll(",", ""))<=0){
    		    							errorMsg = errorMsg + " 单位缴存额或个人缴存额必须大于零 ";
    		    						}
    		    						
    		    					}
    		    					String grjje = cells2[14].getContents().trim()
    		    							.replaceAll(",", "");
    		    					
    		    					String dwjje = cells2[15].getContents().trim()
    		    							.replaceAll(",", "");
    		    					if((Double.parseDouble(grjje) +Double.parseDouble(dwjje))>Double.parseDouble(((Map)listzcxx.get(0)).get("YJCESX").toString())
    		    							|| (Double.parseDouble(grjje) +Double.parseDouble(dwjje))<Double.parseDouble(((Map)listzcxx.get(0)).get("YJCEXX").toString())
    		    							){
    		    						 errorMsg = errorMsg + " 月缴存额超过规定限制 ： 【"+((Map)listzcxx.get(0)).get("YJCESX").toString()+"~"+((Map)listzcxx.get(0)).get("YJCEXX").toString()+"】" ;
    		    					}
    		    					if (!errorMsg.trim().equals("")) {
    		    						errorMsg = "第" + (i -8+ 1) + "条记录,个人账号为:"+grzh+" " + errorMsg;
    		    						Map map=new HashMap();
    		    						map.put("code", 0);
    		    	    				map.put("msg", errorMsg);
    		    	    				map.put("data", "");
    		    	    				listRet.add(map);
    		    						// listRet.add(errorMsg);
    		    					}

    		    					
    		            	}
    		            	Map reqMap1=new HashMap();
		        			reqMap1.put("AUTHORITY", "YBGJJ187");
		        			reqMap1.put("OpenKey", sessionIn.getKEY());
		        			b.setDWZH(dwdm);
		        			reqMap1.put("BODY",b);
		        			OpenKey opk1=new OpenKey();
		        			String result1=opk1.getOpenKey(reqMap1, session);
		        			Map resMap1 = JSONUtil.toMap(result1);
		        			Map mx=JSONUtil.toMap(JSONUtil.ToJsongString2(resMap1.get("body")));
		        			List lx=(List) mx.get("RETDATA");
		        			Map mx2=(Map) lx.get(0);
		        			String LSH=mx2.get("LSH").toString();
    		            	if (listRet.size() == 0) {
    		            		for (int i = 0; i < sheet.getRows() - 11; i++) {
    		            			
    								Cell[] cells2 = sheet.getRow(i + 8);// 获取某一行的所有单元格

    								String grzh = cells2[3].getContents().trim();
    								// String gze =
    								// cells2[10].getContents().trim().replaceAll(",", "");
    								String grjje = cells2[14].getContents().trim()
    										.replaceAll(",", "");
    								
    								String dwjje = cells2[15].getContents().trim()
    										.replaceAll(",", "");
    								
    								
    								String grbl = cells2[11].getContents().trim();
    								String dwbl = cells2[12].getContents().trim();

    								String mobile = cells2[16].getContents().trim();
    								if (mobile.length() > 11)
    									mobile = mobile.substring(0, 11);
    				    			b.setDWZH(dwdm);
    				    			reqMap.put("AUTHORITY", "YBGJJ188");
    				    			reqMap.put("OpenKey", sessionIn.getKEY());
    				    			b.setLSH(LSH);
    				    			b.setGRZH(grzh);
    				    			b.setDWZH(dwdm);
    				    			b.setZJHM(cells2[2].getContents().trim());
    				    			b.setGRJCE(grjje);
    				    			b.setDWJCE(dwjje);
    				    			b.setSJHM(cells2[16].getContents().trim());
    				    			b.setBGQGZJS(cells2[4].getContents().trim().replace(",", ""));
    				    			b.setBGHGZJS(cells2[10].getContents().trim().replace(",", ""));
    				    			sxdate=sxdate.replace("-", "");
    				    			sxdate=sxdate.substring(0,6);
    				    			b.setRQ(sxdate);
    				    			reqMap.put("BODY",b);
    				    			OpenKey opk2=new OpenKey();
    			        			String result2=opk2.getOpenKey(reqMap, session);
    		            		}
    		            		
	    					}
    		            book.close(); 
    		            System.out.println(file.getSize());
    		            String destPath2 = Constant.PK_FILEPATH+"/gjbg/基数核定成功文件/";
    		            File dir2 = new File(destPath2,fileName+s.format(new Date()) );
	    			    FileUtils.copyFile(dir.getAbsoluteFile(), dir2.getAbsoluteFile()); 
    				
    			}
    			else
    			{
    				Map map = new HashMap();
    				map.put("code", 0);
    				map.put("msg", resMap.get("RETURNDESC"));
    				map.put("data", "");
    				listRet.add(map);
    			} }
    			response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(listRet);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);

	           
	       	}
	        catch(Exception e)  {
	        	e.printStackTrace();
	        	
	        }
			return null; 
	    }
	     
	
	@RequestMapping("/test1")
	@ResponseBody
	 public String dn( HttpServletRequest request, HttpSession session,HttpServletResponse response) throws IOException{  
		BODY b=new BODY();
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		b.setDWZH(sessionIn.getDWZH());
		Map reqMap=new HashMap();
		reqMap.put("AUTHORITY", "YBGJJ189");
		reqMap.put("OpenKey", sessionIn.getKEY());
		reqMap.put("BODY",b);
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		Map resMap = JSONUtil.toMap(result);
		Map  mm=  (Map) resMap.get("body");
		List list=(List) mm.get("RETDATA");
		
		String filePath = "";
		try {
			String[] str =System.getProperty("user.dir").split("bin");
			String destPath=str[0]+"\\webapps\\wsyyt\\templete";
			File inputWorkbook = new File(destPath + "/公积金基数核对清单.xls");
//			destPath = destPath + "tmp/";
			SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			String dayStr = outFormat.format(new Date());
			File outputWorkbook = new File( Constant.url
					+ sessionIn.getDWZH() + "_" + dayStr + ".xls");
			Workbook w1 = Workbook.getWorkbook(inputWorkbook);
			WritableWorkbook w2 = Workbook.createWorkbook(
					outputWorkbook, w1);
			w1.close();

			WritableSheet sheet = w2.getSheet(0);
			WritableCell cell = null;
			CellFormat cf = null;
			Label l = null;
			WritableCellFeatures wcf = null;
			Map map=(Map) list.get(0);
			l = new Label(1, 1, sessionIn.getDWMC());
			l.setCellFormat(sheet.getCell(1, 1).getCellFormat());
			sheet.addCell(l);
			l = new Label(1, 2, sessionIn.getDWZH());
			l.setCellFormat(sheet.getCell(1, 2).getCellFormat());
			sheet.addCell(l);
			// l = new Label(1, 3, Util.formatDate5(new Date()));
			// l.setCellFormat(sheet.getCell(1, 3).getCellFormat());
			// sheet.addCell(l);
			Number n = new Number(2, 4, Integer.parseInt(map.get(
					"DWJCBL").toString().trim()));
			((WritableCell) n).setCellFormat(sheet.getCell(2, 4).getCellFormat());
			sheet.addCell((WritableCell) n);
			n = new Number(4, 4, Integer.parseInt(map.get("GRJCBL")
					.toString().trim()));
			((WritableCell) n).setCellFormat(sheet.getCell(4, 4).getCellFormat());
			sheet.addCell((WritableCell) n);

			// n = new Number(7, 4,
			// Integer.parseInt(map.get("单位缴存比例").toString()));
			// n.setCellFormat(sheet.getCell(2, 4).getCellFormat());
			// sheet.addCell(n);
			// n = new Number(9, 4,
			// Integer.parseInt(map.get("个人缴存比例").toString()));
			// n.setCellFormat(sheet.getCell(4, 4).getCellFormat());
			// sheet.addCell(n);
			//				
			if (list != null && list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					map = (Map) list.get(i);
					if (i > 0)
						sheet.insertRow(i + 8);
					n = new Number(0, i + 8, (double) (i + 1));
					n
							.setCellFormat(sheet.getCell(0, 8)
									.getCellFormat());
					sheet.addCell(n);

					l = new Label(1, i + 8, map.get("XINGMING").toString());
					l
							.setCellFormat(sheet.getCell(1, 8)
									.getCellFormat());
					sheet.addCell(l);

					l = new Label(2, i + 8, map.get("ZJHM").toString());
					l
							.setCellFormat(sheet.getCell(2, 8)
									.getCellFormat());
					sheet.addCell(l);

					l = new Label(3, i + 8, map.get("GRZH").toString());
					l
							.setCellFormat(sheet.getCell(3, 8)
									.getCellFormat());
					sheet.addCell(l);

					n = new Number(4, i + 8, Float.parseFloat(map.get(
							"JCJS").toString().trim()));
					n
							.setCellFormat(sheet.getCell(4, 8)
									.getCellFormat());
					sheet.addCell(n);
					n = new Number(5, i + 8, Integer.parseInt(map.get(
							"GRJCBL").toString().trim()));
					n
							.setCellFormat(sheet.getCell(5, 8)
									.getCellFormat());
					sheet.addCell(n);
					n = new Number(6, i + 8, Integer.parseInt(map.get(
							"DWJCBL").toString().trim()));
					n
							.setCellFormat(sheet.getCell(6, 8)
									.getCellFormat());
					sheet.addCell(n);

					Formula formual = new Formula(7, i + 8, "I"	+ (i + 9) + " + J" + (i + 9));
					formual.setCellFormat(sheet.getCell(7, 8).getCellFormat());
					sheet.addCell(formual);

					n = new Number(8, i + 8, Float.parseFloat(map.get(
							"GRJCE").toString().trim()));
					n
							.setCellFormat(sheet.getCell(8, 8)
									.getCellFormat());
					sheet.addCell(n);
					n = new Number(9, i + 8, Float.parseFloat(map.get(
							"DWJCE").toString().trim()));
					n
							.setCellFormat(sheet.getCell(9, 8)
									.getCellFormat());
					sheet.addCell(n);

					
					formual = new Formula(10, i + 8, "N" + (i + 9)+"*100/(C5"+"+E5)");
					formual.setCellFormat(sheet.getCell(10, 8)
							.getCellFormat());
					sheet.addCell(formual);
					
//					formual = new Formula(10, i + 8, "O" + (i + 9)
//							+ "*100/(C5" + "+E5"
//							+ ")" + "+p" + (i + 9) + "*100/(C5" + "+E5)");
//					formual.setCellFormat(sheet.getCell(10, 8)
//							.getCellFormat());
//					sheet.addCell(formual);

					formual = new Formula(11, i + 8, "$E$5");
					formual.setCellFormat(sheet.getCell(11, 8)
							.getCellFormat());
					sheet.addCell(formual);

					formual = new Formula(12, i + 8, "$C$5");
					formual.setCellFormat(sheet.getCell(12, 8)
							.getCellFormat());
					sheet.addCell(formual);

					formual = new Formula(13, i + 8, "o" + (i + 9)
							+ " + p" + (i + 9));
					formual.setCellFormat(sheet.getCell(13, 8)
							.getCellFormat());
					sheet.addCell(formual);
					// //
					// // formual = new
					// Formula(14,i+8,"K"+(i+9)+" * L"+(i+9) + " /100");
					// //
					// formual.setCellFormat(sheet.getCell(14,8).getCellFormat());
					// // sheet.addCell(formual);
					//						
					// formual = new
					// Formula(15,i+8,"K"+(i+9)+" * M"+(i+9) + " /100");
					// formual.setCellFormat(sheet.getCell(15,8).getCellFormat());
					// sheet.addCell(formual);

					l = new Label(14, i + 8, "0");
					l.setCellFormat(sheet.getCell(14, 8)
							.getCellFormat());
					sheet.addCell(l);

					l = new Label(15, i + 8, "0");
					l.setCellFormat(sheet.getCell(15, 8)
							.getCellFormat());
					sheet.addCell(l);

					l = new Label(16, i + 8, map.get("SJHM").toString());
					l.setCellFormat(sheet.getCell(16, 8)
							.getCellFormat());
					sheet.addCell(l);

				}

			}

			w2.write();
			w2.close();

			 filePath =outputWorkbook.getName();
			 Map m=new HashMap();
			 m.put("filePath", filePath);
			 response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(m);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("/test3")
	@ResponseBody
	 public String hd( HttpServletRequest request, HttpSession session,HttpServletResponse response) throws IOException{  
		BODY b=new BODY();
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		b.setDWZH(sessionIn.getDWZH());
		Map reqMap=new HashMap();
		reqMap.put("AUTHORITY", "YBGJJ191");
		reqMap.put("OpenKey", sessionIn.getKEY());
		reqMap.put("BODY",b);
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		Map resMap = JSONUtil.toMap(result);
		 Map m=new HashMap();
		 Map mm=(Map) resMap.get("body");
		 m.put("DWJCEHJ", mm.get("DWJCEHJ"));
		 m.put("GRJCEHJ", mm.get("GRJCEHJ"));
		 m.put("data", mm.get("RETDATA"));
		 m.put("msg", resMap.get("RETURNDESC"));
		 response.setHeader("Content-type", "text/html;charset=UTF-8");
			response.setCharacterEncoding("UTF-8");
			String jsonString = JSONUtil.ToJsongString2(m);
			PrintWriter pw = response.getWriter();
			pw.write(jsonString);
		return null;
	    }  
	
	@RequestMapping(value = "/downloadexcels", produces = {"application/json;charset=UTF-8"},method = {RequestMethod.GET,RequestMethod.POST})
    public void downloadexcels(HttpServletRequest request, HttpServletResponse response) throws IOException {
	   File file=new File(Constant.url2 +request.getParameter("filename"));
	       response.addHeader("Content-Disposition","attachment; filename=" + new String(file.getName().getBytes("GBK"),"ISO8859-1"));
	       FileInputStream fileInputStream = new FileInputStream(file);
	       byte[] by  = new byte[fileInputStream.available()];
	       fileInputStream.read(by);
	       OutputStream outputStream = response.getOutputStream();
	       outputStream.write(by);
	       fileInputStream.close();
	       outputStream.close();
	       file.deleteOnExit();
	   }
	@RequestMapping(value = "/openphoto", produces = {"application/json;charset=UTF-8"},method = {RequestMethod.GET,RequestMethod.POST})
    public void openphoto(HttpServletRequest request, HttpServletResponse response,String ID,String filename) throws IOException {
		  try {
			  File file=new File(Constant.PK_FILEPATH+"/1/1234/4567/8901/"+ID+"/28/"+filename);
		       response.addHeader("Content-Disposition","attachment; filename=" + new String(file.getName().getBytes("GBK"),"ISO8859-1"));
		       FileInputStream fileInputStream = new FileInputStream(file);
		       byte[] by  = new byte[fileInputStream.available()];
		       fileInputStream.read(by);
		       OutputStream outputStream = response.getOutputStream();
		       outputStream.write(by);
		       fileInputStream.close();
		       outputStream.close();
		       file.deleteOnExit();
			} catch (Exception e) {
				// TODO: handle exception
			} 
	   }
	@RequestMapping("/delete")
	@ResponseBody
	 public String delete( HttpServletRequest request, HttpSession session,HttpServletResponse response,String ID) throws IOException{  
		BODY b=new BODY();
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		b.setDWZH(sessionIn.getDWZH());
		Map reqMap=new HashMap();
		reqMap.put("AUTHORITY", "YBGJJ217");
		b.setID(ID);
		reqMap.put("OpenKey", sessionIn.getKEY());
		reqMap.put("BODY",b);
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		Map resMap = JSONUtil.toMap(result);
		 Map mm=(Map) resMap.get("body");
		 Map map=new HashMap();
		 	map.put("code", 0); 
			map.put("msg", null);
			map.put("data", mm.get("RETDATA"));
			response.setHeader("Content-type", "text/html;charset=UTF-8");
			response.setCharacterEncoding("UTF-8");
			String jsonString = JSONUtil.ToJsongString2(map);
			PrintWriter pw = response.getWriter();
			pw.write(jsonString);
		return null;
	    }  
}
